﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

using PortalIntranet.DatabaseComponents.Comun;
using System.Data.Entity.ModelConfiguration;
using PortalIntranet.DatabaseComponents.WebParts;

namespace PortalIntranet.DatabaseComponents.Administracao
{
	[Serializable]
	[Table("WebPages")]
	public class WebPage : Entidade
	{
		public WebPage()
		{
			this.WebParts = new HashSet<WebPart>();
		}

		[Required, MaxLength(50)]
		public string Nome { get; set; }

		[Required, MaxLength(50)]
		public string Slug { get; set; }

		public int Ordem { get; set; }

		public bool Principal { get; set; }

		#region Departamento
		public int DepartamentoId { get; set; }

		public virtual Departamento Departamento { get; set; }
		#endregion

		#region TipoLayout
		public int TipoLayoutId { get; set; }

		public virtual TipoLayout TipoLayout { get; set; }
		#endregion

		#region Navegação
		public virtual ICollection<WebPart> WebParts { get; set; }
		#endregion
	}

	internal class WebPageConfiguration : EntityTypeConfiguration<WebPage>
	{
		internal WebPageConfiguration()
		{
			this.HasOptional(i => i.Departamento)
				.WithMany(u => u.WebPages)
				.HasForeignKey(i => i.DepartamentoId);
		}
	}
}
